package jmm.threadPool.completionService;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

public class CompletionServiceDemo4 {

    public static void main(String[] args) throws InterruptedException {
        // 创建线程池
        ExecutorService executor =
                Executors.newFixedThreadPool(3);

        List<String> taskList = new ArrayList(5);
        taskList.add("w");
        taskList.add("s");
        taskList.add("C");


        List<Callable<String>> callables = new ArrayList<>();
        taskList.stream().forEach(task->callables.add(()->{
            System.out.println("hello--->" + task);
            return task;
        }));

        List<Future<String>> futures = executor.invokeAll(callables);

        for (Future<String> future : futures) {
            try {
                System.out.println(future.get());
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        }
    }
}
